package com.wenkaihu.android.chess.socket;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;

import android.util.Log;

import com.wenkaihu.android.chess.model.PaceblePoint;

public class Client implements Runnable {
	private static final int SERVERPORT = 8888;
	private static final String SERVERIP = "192.168.30.201";
	private PaceblePoint mPoint;
	private PaceblePoint receivePoint;
	
	public Client(PaceblePoint mPoint) {
		this.mPoint = mPoint;
	}
	
	public void run() {
		try {
			InetAddress serverAddr = InetAddress.getByName(SERVERIP); 
			Log.d("chess", "C #Start Connecting...");
			Socket socket = new Socket(serverAddr, SERVERPORT);
			Log.d("chess", "C #Connected");

			// initial the object parameter
			Log.d("chess", "C #Sending: Point = " + mPoint.toString());
			
			(new ObjectOutputStream(socket.getOutputStream())).writeObject(mPoint);

			Log.d("chess", "C #Sended");
			while(true){
				receivePoint = (PaceblePoint) (new ObjectInputStream(socket.getInputStream())).readObject();
				Log.d("chess", "C #Receive Point is#" + receivePoint.toString());
			}
			//socket.close();
		} catch (Exception e) {
			Log.e("chess", "C #Get Exception #" + e);
		}
	}
}